package com.efounder.frame.utils;

import androidx.drawerlayout.widget.DrawerLayout;
import android.view.View;

import com.nineoldandroid.view.ViewHelper;

/**
 * Created by hudq on 2016/9/5. 抽屉工具类
 */
public class DrawerUtils {

    public static void changeDrawerLayoutContentView(DrawerLayout drawerLayout,View drawerView, float slideOffset){
        View mContent = drawerLayout.getChildAt(0);
        View mMenu = drawerView;
        float scale = 1 - slideOffset;
        float rightScale = 0.8f + scale * 0.2f;
        // rightScale  leftScale 都设置为1 就没有缩放了 yqs
        if (drawerView.getTag().equals("LEFT")) {

            float leftScale = 1 - 0.3f * scale;

            leftScale=1;
            rightScale =1;

            ViewHelper.setScaleX(mMenu, leftScale);
            ViewHelper.setScaleY(mMenu, leftScale);
            ViewHelper.setAlpha(mMenu, 0.6f + 0.4f * (1 - scale));
            ViewHelper.setTranslationX(mContent,
                    mMenu.getMeasuredWidth() * (1 - scale));
            ViewHelper.setPivotX(mContent, 0);
            ViewHelper.setPivotY(mContent,
                    mContent.getMeasuredHeight() / 2);
            mContent.invalidate();
            ViewHelper.setScaleX(mContent, rightScale);
            ViewHelper.setScaleY(mContent, rightScale);
        } else {
            ViewHelper.setTranslationX(mContent,
                    -mMenu.getMeasuredWidth() * slideOffset);
            ViewHelper.setPivotX(mContent, mContent.getMeasuredWidth());
            ViewHelper.setPivotY(mContent,
                    mContent.getMeasuredHeight() / 2);
            mContent.invalidate();
            ViewHelper.setScaleX(mContent, rightScale);
            ViewHelper.setScaleY(mContent, rightScale);
        }
    }
}
